<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class CateController extends Controller
{
    //
    public function ajaxreq(Request $request)
    {
    	$id = $request ->input('id');
    	// return $id;
    	$res = DB::table('cate') -> where('pid',$id) -> lists('name');
    	return response()->json($res);
    }

    public function spage()//新品专区
    {
        $title = '新品专区';
        $data = array('12.jpg'=>0,'13.jpg'=>1,'14.jpg'=>2,'15.jpg'=>3,'16.jpg'=>4,'17.jpg'=>5);
        $res = DB::table('goods')->where('gcate',1)->limit(8)->get();
        $data['12.jpg']  = $res;
        $res = DB::table('goods')->where('gcate',2)->limit(8)->get();
        $data['13.jpg']  = $res;
        $res = DB::table('goods')->where('gcate',3)->limit(8)->get();
        $data['14.jpg']  = $res;
        $res = DB::table('goods')->where('gcate',5)->limit(8)->get();
        $data['15.jpg']  = $res;
        $res = DB::table('goods')->where('gcate',7)->limit(8)->get();
        $data['16.jpg']  = $res;
        $res = DB::table('goods')->where('gcate',8)->limit(8)->get();
        $data['17.jpg']  = $res;
     
       return view('home.cate.newFood',['title'=> $title,'data'=>$data]);
    }

    public function tpage()//优质生活
    {
        $title = '优质生活';
        $data = array('22.jpg'=>0,'23.jpg'=>1,'24.jpg'=>2);
        $res = DB::table('goods')->where('gcate',1)->limit(8)->get();
        $data['22.jpg']  = $res;
        $res = DB::table('goods')->where('gcate',2)->limit(8)->get();
        $data['23.jpg']  = $res;
        $res = DB::table('goods')->where('gcate',3)->limit(8)->get();
        $data['24.jpg']  = $res;
     
       return view('home.cate.tpage',['title'=> $title,'data'=>$data]);
    }

    public function brand($name)
    {
        //id能收到
        $title = $name.'品牌';
        $res = DB::table('goods') ->where('gbrand','like','%'.$name.'%')->get();
        
        return view('home.cate.z-page',['title'=>$title,'data'=>$res]);
    }

    public function zpage($id)
    {
    	
        //$id能接收到
        switch($id){
            case 1:
            $title='进口水果';
            break;
            case 2:
            $title='国产水果';
            break;
            case 3:
            $title='精选肉类';
            break;
            case 4:
            $title='禽类蛋品';
            break;
            case 5:
            $title='15.jpg';
            break;
            case 6:
            $title='乳品糕点';
            break;
            case 7:
            $title='新鲜蔬菜';
            break;
            case 8:
            $title='方便速食';
            break;
            case 9:
            $title='油粮杂货';
            break;

        }
        $res = DB::table('goods')->where('gcate',$id) ->get();
       
    	return view('home.cate.z-page',['title'=>$title,'data'=>$res]);
    }
}
